<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <title>DIDIFight</title>
	<#include "common/header.ftl"/>
    <script type="text/javascript" src="/js/plugins/jquery.form.js"></script>
    <script type="text/javascript" src="/js/plugins/jquery-validation/jquery.validate.js"></script>
    <script type="text/javascript" src="/js/plugins/jquery.twbsPagination.min.js"></script>

    <script type="text/javascript">
        $(function () {
            $(function () {
                //点击查询按钮
                $("#query").click(function () {
                    window.location.reload();
                });

                //点击更新公众号菜单按钮
                $("#updateRemoteMenuBtn").click(function () {
                    $.get("/menuRemoteUpdate",function (data) {
                        if (data.errmsg == "ok"){
                            $.messager.popup("更新成功");
                            location.reload();
                        }else {
                            $.messager.popup(data.errcode+":"+data.errmsg);
                        }
                    },"json")
                })

                //点击新增按钮
                $("#addMenuBtn").click(function () {
                    $("#editForm").clearForm(true);
                    $("#menuModal").modal("show");
                });
                //点击保存按钮
                $("#saveBtn").click(function () {
                    $("#editForm").ajaxSubmit({
                        datatype: "json",
                        success: function (data) {
                            if (data.success) {
                                $("#currentPage").val(1);
                                $("#searchForm").submit();
                            } else {
                                $.messager.popup(data.msg);
                            }
                        }
                    })
                });
                //点击修改按钮
                $(".edit_Btn").click(function () {
                    $("#editForm").clearForm(true);
                    //数据回显
                    var data = $(this).data("json");
                    $("#menuId").val(data.id);
                    $("#name").val(data.name);
                    $("#key").val(data.key);
                    $("#type").val(data.type);
                    $("#url").val(data.url);
                    $("#menuModal").modal("show");
                })
            });
        });
    </script>
</head>

<body>
<div class="container">
		<#include "common/top.ftl"/>
    <div class="row">
    <div class="col-sm-3">
        <#assign currentMenu = "menu" />
        <#include "common/menu.ftl" />
    </div>
        <div class="col-sm-9">
            <div class="page-header">
                <center>
                    <h3>菜单管理</h3>
                </center>
            </div>
            <div class="row">
                <!-- 提交分页的表单 -->
                <form id="searchForm" class="form-inline" method="post" action="/menu">
                    <input type="hidden" name="currentPage" id="currentPage" value=""/>
                    <div class="form-group">
                        <button id="query" type="button" class="btn btn-success"><i class="icon-search"></i> 查询</button>
                        <a href="javascript:void(-1);" class="btn btn-success" id="addMenuBtn">添加菜单</a>
                        <a href="javascript:void(-1);" class="btn btn-success" id="updateRemoteMenuBtn">更新公众号菜单</a>
                    </div>
                </form>
            </div>
            <div class="row">
                <table class="table">
                    <thead>
                    <tr>
                        <th>NAME</th>
                        <th>KEY</th>
                        <th>TYPE</th>
                        <th>URL</th>
                        <th>OPTION</th>
                    </tr>
                    </thead>
                    <tbody>
						<#list menus as vo>
                        <tr>
                            <td>${vo.name!''}</td>
                            <td>${vo.key!''}</td>
                            <td>${vo.type!''}</td>
                            <td>${vo.url!''}</td>
                            <td>
                                <a href="javascript:void(-1);" class="edit_Btn" data-json='${vo.jsonString!''}'>修改</a>
                            </td>
                        </tr>
                        </#list>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

<div id="menuModal" class="modal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">编辑/增加</h4>
            </div>
            <div class="modal-body">
                <form id="editForm" class="form-horizontal" method="post" action="/menuLocalUpdate"
                      style="margin: -3px 118px">
                    <input id="menuId" type="hidden" name="id" value=""/>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">NAME</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="name" name="name" placeholder="NAME">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">KEY</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="key" name="key" placeholder="KEY">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">TYPE</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="type" name="type" placeholder="TYPE">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">URL</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="url" name="url" placeholder="URL">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <a href="javascript:void(0);" class="btn btn-success" id="saveBtn" aria-hidden="true">保存</a>
                <a href="javascript:void(0);" class="btn" data-dismiss="modal" aria-hidden="true">关闭</a>
            </div>
        </div>
    </div>
</div>
</body>
</html>